<template>
	<view>
		<!-- 更换设计师 -->
		<changeManCom
			@closeFunc="close('design_changeDesigner')"
			:show="changShow"
			:type="value == 'design_changeDesigner' ? 2 : 5"
			:projectId="oper_item.id"
			@changeManSuccessFunc="changeManSuccessFunc"
		></changeManCom>
		<!-- 分配勘场工程经理 -->
		<u-picker
			title="工程经理"
			:show="gcjlShow2"
			:columns="[engineeringSupervisionList]"
			keyName="name"
			@close="choosefpgcjFunc2"
			@cancel="choosefpgcjFunc2"
			@confirm="gcjlConfirm"
			closeOnClickOverlay
		></u-picker>
		<u-popup :show="gcjlShow" @close="close('design_engineeringManager')" mode="bottom" closeable round="10">
			<view class="fp-box-title">分配勘场工程经理</view>
			<view class="fp-box">
				<u--form labelPosition="top" :model="fpgcjlRuleForm" labelWidth="auto">
					<u-form-item required label="工程经理" borderBottom @click="choosefpgcjFunc">
						<u--input v-model="fpgcjlRuleForm.engineering_manager_name" readonly border="none" placeholder="选择工程经理" suffixIcon="arrow-right"></u--input>
					</u-form-item>
					<u-form-item label="备注">
						<u--textarea v-model="fpgcjlRuleForm.remark"></u--textarea>
					</u-form-item>
				</u--form>
				<u-button type="primary" text="提交" color="#3B75FF" :customStyle="{ marginTop: '30rpx' }" @click="submitFunc"></u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
export default {
	name: 'siteSurveyOperate',
	props: {
		value: {
			type: String,
			default: ''
		},
		oper_item: {
			type: Object,
			default: {}
		}
	},
	watch: {
		value(val) {
			let that = this;
			switch (val) {
				// 更换设计师
				case 'design_changeDesigner':
					that.changShow = true;
					break;
				// 分配勘场工程经理
				case 'design_engineeringManager':
					this.getEngineering_directorList();
					this.gcjlShow = true;
					break;
				// 更换勘场工程经理
				case 'siteSurvey_editGcjl':
					that.changShow = true;
					break;
				// 提交勘场报告
				case 'siteSurvey_submitBg':
					uni.navigateTo({
						url: '/pagesC/designManagement/addSurveyReport/addSurveyReport?id=' + this.oper_item.id
					});
					this.close('siteSurvey_submitBg');
					break;
				// 提交勘场资料
				case 'siteSurvey_submitZl':
					uni.navigateTo({
						url: '/pagesC/designManagement/addSurveyData/addSurveyData?id=' + this.oper_item.id
					});
					this.close('siteSurvey_submitZl');
					break;

				default:
			}
		}
	},
	data() {
		return {
			changShow: false,
			engineeringSupervisionList: [], //工程经理列表
			fpgcjlRuleForm: {
				engineering_manager_id: '',
				engineering_manager_name: '',
				remark: ''
			},
			gcjlShow: false, //分配工程经理弹窗
			gcjlShow2: false //工程经理弹窗
		};
	},
	methods: {
		// 更换工程经理完成
		changeManSuccessFunc() {
			this.$emit('submit', this.value);
			this.close('design_changeDesigner');
		},
		close(type) {
			switch (type) {
				case 'design_changeDesigner':
					this.changShow = false;
					break;
				case 'design_engineeringManager':
					this.gcjlShow = false;
					break;

				default:
			}
			this.$emit('update:value', '');
			this.fpgcjlRuleForm = {
				engineering_manager_id: '',
				engineering_manager_name: '',
				remark: ''
			};
		},
		// 工程经理列表
		getEngineering_directorList() {
			var obj = {
				page: 1,
				num: 9999,
				keyword: '',
				province_id: '',
				city_id: '',
				county_id: '',
				identity: 2,
				position_id_arr: [7]
			};
			this.$Apipc
				.getAdminList(obj)
				.then((res) => {
					console.log(res, '工程经理');
					if (res.code == 200) {
						this.engineeringSupervisionList = res.data.list;
					}
				})
				.catch((err) => {});
		},
		// 分配勘场工程经理确认
		submitFunc() {
			let fpgcjlRuleForm = this.fpgcjlRuleForm;
			if (!fpgcjlRuleForm.engineering_manager_name) {
				uni.showToast({
					title: '请选择工程经理',
					icon: 'error'
				});
				return;
			}
			uni.showLoading({
				mask: true
			});
			this.$Apipc
				.assignEngineeringManager({
					project_id: this.oper_item.id,
					engineering_manager_id: fpgcjlRuleForm.engineering_manager_id,
					remark: fpgcjlRuleForm.remark,
					type: 1,
					engineering_supervision_id: ''
				})
				.then((res) => {
					uni.hideLoading();
					console.log(res, '分配工程经理');
					if (res.code == 200) {
						this.$emit('submit', this.value);
						this.close('design_engineeringManager');
					}
					uni.showToast({
						icon: res.code == 200 ? 'success' : 'error',
						title: res.code == 200 ? '处理成功' : res.message
					});
				});
		},
		// 选择工程经理开启
		choosefpgcjFunc() {
			this.gcjlShow = false;
			this.gcjlShow2 = true;
		},
		// 选择工程经理关闭
		choosefpgcjFunc2() {
			this.gcjlShow = true;
			this.gcjlShow2 = false;
		},
		// 确认选择工程经理
		gcjlConfirm(e) {
			console.log(e);
			this.fpgcjlRuleForm.engineering_manager_id = e.value[0].id;
			this.fpgcjlRuleForm.engineering_manager_name = e.value[0].name;
			this.choosefpgcjFunc2();
		}
	}
};
</script>

<style lang="scss" scoped>
.fp-box-title {
	height: 46px;
	border-bottom: 2rpx solid #efefef;
	text-align: center;
	line-height: 46px;
	font-size: 30rpx;
}
.fp-box {
	width: 100%;
	padding: 20rpx 30rpx 20rpx;
	box-sizing: border-box;
}
</style>
